﻿using Leeder.Business;
using ScanConfirm.Model;
using ScanConfirm.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ScanConfirm.Business
{
    public class PartsCodeEquateBLL : BaseBLL<PartsCodeEquateModel, PartsCodeEquateService>
    {
        public PartsCodeEquateBLL()
        {
            Service = new PartsCodeEquateService();
        }
        public List<PartsCodeEquateModel> GetModelList()
        {
            return Service.Query().ActivedObj;
        }

        public PartsCodeEquateModel GetPartsSetupByCode(string code,string codeEquate)
        {
            return Service.Query(p => p.PartsCode == code && p.PartsCodeEquate == codeEquate).ActivedObj.FirstOrDefault();
        }

        public List<PartsCodeEquateModel> GetModelListByCondition(string code)
        {
            var query = Service.CreateCondition();
            if (!string.IsNullOrEmpty(code) && code != "--ALL--")
                query.AddConditon(p => p.DisplayCode == code);
            return Service.Query(query).ActivedObj;
        }

        public List<PartsCodeEquateModel> GetModelListByEquate(string code)
        {
            var query = Service.CreateCondition();
            query.AddConditon(p => p.PartsCode == code);
            return Service.Query(query).ActivedObj;
        }

        public bool IsEquate(string code,string codeEquate)
        {
            var query = Service.CreateCondition();
            query.AddConditon(p => p.PartsCode == code && p.PartsCodeEquate == codeEquate);
            var list = Service.Query(query).ActivedObj;
            if(list.Count > 0)
                return true;
            else
                return false;
        }

    }
}
